package com.bailong.administrator.ausedcar.ui.detail;

import android.os.Handler;
import android.util.Log;

import com.bailong.administrator.ausedcar.bean.DetailBean;
import com.bailong.administrator.ausedcar.bean.HomeHotBean;
import com.bailong.administrator.ausedcar.bean.HomeLikeBean;
import com.bailong.administrator.ausedcar.bean.HomeShowBean;
import com.bailong.administrator.ausedcar.config.UrlConfig;

import java.util.HashMap;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2016/9/6.
 */
public class DetailPresenter implements DetailContract.Presenter {
    private DetailContract.Mode mode;
    private DetailContract.View view;

    public DetailPresenter(DetailContract.View view) {
        this.view = view;
        this.mode=new DetailMode();
    }

    @Override
    public void loadDetailBean() {
        Map<String,String> hashMap= new HashMap<>();
        hashMap.put(UrlConfig.parmas._apikey,"92ebde");
        hashMap.put(UrlConfig.parmas.appver,UrlConfig.HomeLikeValues.appver);
        hashMap.put(UrlConfig.parmas.channel,UrlConfig.HomeLikeValues.channel);
        hashMap.put(UrlConfig.parmas.cityid,UrlConfig.HomeLikeValues.cityid);
        hashMap.put(UrlConfig.parmas.nb,UrlConfig.HomeLikeValues.nb);
        hashMap.put(UrlConfig.parmas.os,UrlConfig.HomeLikeValues.os);
        hashMap.put(UrlConfig.parmas.carid,"13323326");


        mode.loadDetailBean(new Callback<DetailBean>() {
            @Override
            public void onResponse(Call<DetailBean> call, Response<DetailBean> response) {
                if (response.isSuccessful()){
                    final DetailBean body = response.body();
                    Handler handler=new Handler();
                    handler.post(new Runnable() {
                        @Override
                        public void run() {

                            view.onResponse(body);

                        }
                    });
                }
            }

            @Override
            public void onFailure(Call<DetailBean> call, Throwable t) {
                Log.i("jerry", "on==========执行啦sss"+t.toString());
            }
        },hashMap);
    }
}
